import Vue from 'vue';
import Router from 'vue-router';
import Main from '@components/Main';

Vue.use(Router);

const router = new Router({
	routes: [
		{
			path: '/login',
			name: 'login',
			component: () => import('@pages/login/Login')
    },
    {
			path: '/',
      component: Main,
      meta: {
				title: '首页'
			},
			children: [
        {
					name: 'notice',
					path: 'notice',
					component: () => import('@pages/notice/NoticeList'),
					meta: {
						isCheckedLogin: true,
						title: '通知消息'
					}
				},
      ]
    },
		{
			path: '/orders',
			name: 'orders',
			component: Main,
			meta: {
				title: '我的订单'
			},
			children: [
				{
					name: 'orders.video',
					path: 'video',
					component: () => import('@pages/orders/video/Orderlist'),
					meta: {
						isCheckedLogin: true,
						title: '视频会诊'
					}
				},
				{
					name: 'orders.tuwen',
					path: 'tuwen',
					component: () => import('@pages/orders/tuwen/Orderlist'),
					meta: {
						isCheckedLogin: true,
						title: '图文会诊'
					}
				},
				{
					name: 'orders.detail',
					desc: '视频订单详情',
					path: 'video/:id',
					component: () => import('@pages/orders/video/Detail'),
					meta: {
						isCheckedLogin: true,
						title: '订单详情'
					}
				}
			]
		},
		{
			path: '/account',
      name: 'account',
      component: Main,
      meta: {
				title: '账户明细'
			},
			children: [
				{
					name: 'account.income',
					path: 'income',
					component: () => import('@pages/account/Income'),
					meta: {
						isCheckedLogin: true,
						title: '收支记录'
					}
				},
				{
					name: 'account.applyfor',
					path: 'applyfor',
					component: () => import('@pages/account/Applyfor'),
					meta: {
						isCheckedLogin: true,
						title: '提现申请'
					}
				}
			]
		},
		{
			path: '/setting',
			name: 'setting',
			component: Main,
			meta: {
				title: '我的设置'
			},
			children: [
				{
					name: 'setting.videoScheduling',
					path: 'video_scheduling',
					component: () => import('@pages/setting/VideoScheduling'),
					meta: {
						isCheckedLogin: true,
						title: '视频会诊排班'
					}
				},
				{
					name: 'setting.visitTimeSetting',
					path: 'visit_time',
					component: () => import('@pages/setting/VisitTimeSetting'),
					meta: {
						isCheckedLogin: true,
						title: '出诊时间设置'
					}
				},
				{
					name: 'setting.serviceSetting',
					path: 'service',
					component: () => import('@pages/setting/ServiceSetting'),
					meta: {
						isCheckedLogin: true,
						title: '服务设置'
					}
				}
			]
		}
	]
});

// 导航守卫(路由守卫)
router.beforeEach((to, from, next) => {
	// 判断是否是登录状态
	var _token_id = window.sessionStorage.getItem('_token_id');
	var _token_uid = window.sessionStorage.getItem('_token_uid');
	var isCheckedLogin = to.meta.isCheckedLogin;
	// if (to.fullPath === '/login') {
	//   next();
	// } else if (isCheckedLogin && (!_token_id || _token_id === '' || !_token_uid || _token_uid === '')) {
	//   next('/login');
	// } else {
	//   next();
  // }
  
	next();
});

export default router;
